﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GameLib.Utils;
using System.Windows.Shapes;
using System.Windows.Media;
using System.Windows;
using System.Windows.Controls;
using GameLib.WorldMap;

namespace Sandbox.Scene.Elements
{
	class MapVertexCursor : MapSceneObject
	{
		const double CursorRadius = 15;

		public MapVertexCursor()
		{
			m_Cursor = new Ellipse();
			m_Cursor.IsHitTestVisible = false;
			m_Cursor.Width = CursorRadius * 2;
			m_Cursor.Height = CursorRadius * 2;
			m_Cursor.StrokeThickness = 5;
			m_Cursor.Stroke = new SolidColorBrush(Colors.Red);
			m_Cursor.RenderTransform = new TranslateTransform(-CursorRadius, -CursorRadius);
		}

		public Color CursorColor
		{
			get { return (m_Cursor.Stroke as SolidColorBrush).Color; }
			set { (m_Cursor.Stroke as SolidColorBrush).Color = value; }
		}

		protected override void Display()
		{
			SceneCanvas.Children.Add(m_Cursor);
		}

		protected override void Disappear()
		{
			SceneCanvas.Children.Remove(m_Cursor);
		}

		public MapVertex? Vertex
		{
			get { return m_Vert; }
			set
			{
				if (m_Vert != value)
				{
					m_Vert = value;

					if (m_Vert.HasValue)
					{
						m_Cursor.Opacity = 1;
						Point vertPt = Scene.GetVertexPoint(m_Vert.Value);
						m_Cursor.SetValue(Canvas.LeftProperty, vertPt.X);
						m_Cursor.SetValue(Canvas.TopProperty, vertPt.Y);
					}
					else
					{
						m_Cursor.Opacity = 0;
					}
		
				}
			}
		}

		private MapVertex? m_Vert = new MapVertex();
		private Ellipse m_Cursor;

	}
}
